var subscribeModule = angular.module('subscribeModule', []);

subscribeModule.factory('sharedSubscribers', ['$http', '$rootScope', function($http, $rootScope) {
  subscribers = []; //init

  return {
    getSubscribers: function() {
      return $http.get(base_url + 'ajax/getsubscribers').then(function (response) {
        subscribers = response.data;
        $rootScope.$broadcast('handleSubscribersBroadcast', subscribers);
        return subscribers;
      });
    },
    addSubscriber: function(emailAddress) {
      return $http({
        headers: {'Content-Type': 'application/x-www-form-urlencoded'},
        url: base_url + 'ajax/addsubscriber',
        method: "POST",
        data:$.param({email: emailAddress})
      })
        .success(function(addData) {
          alert(addData);
        })
    }
  }
}]);